import { fchmod, writeFile } from 'fs';
import { createWriteStream } from 'fs';


writeFile('./bbb.txt','hello world',{
    encoding:'utf-8',
    flag:'a+'   //使用追加模式
},(err)=>{
    console.log('写入文件结果：',err);
});

const writeStream =createWriteStream('./ccc.txt',{flags:'a'});

writeStream.on('open',(fd) =>{
    console.log('文件被打开',fd);
});

writeStream.write('codewhy');
writeStream.write('aaaaaa');
writeStream.write('bbbbbb',(err)=>{
    console.log('写入完成：',err);
});

writeStream.on('finish',()=>{
    console.log('写入完成了');
});

writeStream.on('close',()=>{
    console.log('文件被关闭');
});

writeStream.end('hhhh');